package com.itheima.mq;

import com.itheima.utils.SMSUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/18 11:59
 * @description：
 */
@Component
public class SendSmsCodeConsumer {

    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @RabbitListener(queues = "sms_queue")
    public void receiveSmsCode(String telephone){
        String smsCode = SMSUtils.sendShortMessage(telephone);
        redisTemplate.opsForValue().set("sms:code:"+telephone,smsCode);
        redisTemplate.expire("sms:code:"+telephone,5, TimeUnit.MINUTES);

    }
}
